package io.github.heollhai.common.config.security.handler;



import io.github.heollhai.common.result.Result;
import io.github.heollhai.common.utils.ResponseUtils;
import jakarta.servlet.ServletException;
import jakarta.servlet.http.HttpServletRequest;
import jakarta.servlet.http.HttpServletResponse;
import org.springframework.security.access.AccessDeniedException;
import org.springframework.security.web.access.AccessDeniedHandler;
import org.springframework.stereotype.Component;

import java.io.IOException;

/**
 * @Author: lmf
 * @Create: 2024/8/6 14:31
 * Description: 权限访问出现异常时回调方法 (权限不足自定义拦截处理)
 */
@Component
public class AccessDeniedHandlerImpl implements AccessDeniedHandler {
    @Override
    public void handle(HttpServletRequest request, HttpServletResponse response, AccessDeniedException accessDeniedException) throws IOException, ServletException {
        Result<String> result = Result.fail("权限不足");
        ResponseUtils.writeJson(response, result);
    }
}
